<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .todos-item {
        transition: all 1s;
        display: inline-block;
        margin-right: 10px;
      }
      .todos-enter,
      .todos-leave-to {
        opacity: 0;
        transform: translateY(30px);
      }
      .todos-leave-active {
        position: absolute;
      }
    </style>
  </head>
  <body>
    <div id="todos-demo" class="demo">
      <button v-on:click="shuffle">Shuffle</button>
      <button v-on:click="add">Add</button>
      <button v-on:click="remove">Remove</button>
      <transition-group name="todos" tag="p">
        <span v-for="item in items" v-bind:key="item" class="todos-item">
          {{ item }}
        </span>
      </transition-group>
    </div>
    <script src="vue.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.14.1/lodash.min.js"></script>
    <script>
      new Vue({
        el: "#todos-demo",
        data: {
          items: [1, 2, 3, 4, 5, 6, 7, 8, 9],
          nextNum: 10,
        },
        methods: {
          randomIndex: function () {
            return Math.floor(Math.random() * this.items.length);
          },
          add: function () {
            this.items.splice(this.randomIndex(), 0, this.nextNum++);
          },
          remove: function () {
            this.items.splice(this.randomIndex(), 1);
          },
          shuffle: function () {
            this.items = _.shuffle(this.items);
          },
        },
      });
    </script>
  </body>
</html>
